<template>
  <el-dialog :title="!dataForm.id ? '新增' : '修改'" :close-on-click-modal="false" :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()"
      label-width="80px">
      <el-form-item label="用户id" prop="userId">
        <el-input v-model="dataForm.userId" placeholder="用户id"></el-input>
      </el-form-item>
      <el-form-item label="所属学院" prop="college">
        <el-input v-model="dataForm.college" placeholder="所属学院"></el-input>
      </el-form-item>
      <el-form-item label="项目标题" prop="title">
        <el-input v-model="dataForm.title" placeholder="项目标题"></el-input>
      </el-form-item>
      <el-form-item label="项目概要" prop="outline">
        <el-input v-model="dataForm.outline" placeholder="项目概要"></el-input>
      </el-form-item>
      <el-form-item label="文件名" prop="file">
        <el-input v-model="dataForm.file" placeholder="文件名"></el-input>
      </el-form-item>
      <el-form-item label="指导老师姓名" prop="teacherName">
        <el-input v-model="dataForm.teacherName" placeholder="指导老师姓名"></el-input>
      </el-form-item>
      <el-form-item label="总分" prop="sum">
        <el-input v-model="dataForm.sum" placeholder="总分"></el-input>
      </el-form-item>
      <el-form-item label="平均分" prop="average">
        <el-input v-model="dataForm.average" placeholder="平均分"></el-input>
      </el-form-item>
      <el-form-item label="评分总人数" prop="peopleNumber">
        <el-input v-model="dataForm.peopleNumber" placeholder="评分总人数"></el-input>
      </el-form-item>
<!--      <el-form-item label="评审状态" prop="statu">
        <el-radio-group v-model="dataForm.statu">
          <el-radio :label="2">不通过</el-radio>
          <el-radio :label="1">通过</el-radio>
          <el-radio :label="0">审核中</el-radio>
        </el-radio-group>


      </el-form-item> -->
      <el-form-item label="比赛类型" prop="projectType">
        <el-input v-model="dataForm.projectType" placeholder="比赛类型"></el-input>
      </el-form-item>
      <el-form-item label="项目类型" prop="type">
        <el-input v-model="dataForm.type" placeholder="项目类型"></el-input>
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data() {
      return {
        visible: false,
        dataForm: {
          id: 0,
          userId: '',
          college: '',
          title: '',
          outline: '',
          file: '',
          teacherName: '',
          sum: '',
          average: '',
          peopleNumber: '',
          // statu: '',
          projectType: '',
          type: '',
          createTime: ''
        },
        dataRule: {
          userId: [{
            required: true,
            message: '用户id不能为空',
            trigger: 'blur'
          }],
          college: [{
            required: true,
            message: '所属学院不能为空',
            trigger: 'blur'
          }],
          title: [{
            required: true,
            message: '项目标题不能为空',
            trigger: 'blur'
          }],
          outline: [{
            required: true,
            message: '项目概要不能为空',
            trigger: 'blur'
          }],
          file: [{
            required: true,
            message: '文件名不能为空',
            trigger: 'blur'
          }],
          teacherName: [{
            required: true,
            message: '指导老师姓名不能为空',
            trigger: 'blur'
          }],
          sum: [{
            required: true,
            message: '总分不能为空',
            trigger: 'blur'
          }],
          average: [{
            required: true,
            message: '平均分不能为空',
            trigger: 'blur'
          }],
          peopleNumber: [{
            required: true,
            message: '评分总人数不能为空',
            trigger: 'blur'
          }],
          statu: [{
            required: true,
            message: '评审状态不能为空',
            trigger: 'blur'
          }],
          projectType: [{
            required: true,
            message: '比赛类型不能为空',
            trigger: 'blur'
          }],
          type: [{
            required: true,
            message: '项目类型不能为空',
            trigger: 'blur'
          }],
          createTime: [{
            required: true,
            message: '创建时间不能为空',
            trigger: 'blur'
          }]
        }
      }
    },
    methods: {
      init(id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/sys/college/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({
              data
            }) => {
              if (data && data.code === 0) {
                this.dataForm.userId = data.college.userId
                this.dataForm.college = data.college.college
                this.dataForm.title = data.college.title
                this.dataForm.outline = data.college.outline
                this.dataForm.file = data.college.file
                this.dataForm.teacherName = data.college.teacherName
                this.dataForm.sum = data.college.sum
                this.dataForm.average = data.college.average
                this.dataForm.peopleNumber = data.college.peopleNumber
                // this.dataForm.statu = data.college.statu
                this.dataForm.projectType = data.college.projectType
                this.dataForm.type = data.college.type
                this.dataForm.createTime = data.college.createTime
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit() {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/sys/college/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'userId': this.dataForm.userId,
                'college': this.dataForm.college,
                'title': this.dataForm.title,
                'outline': this.dataForm.outline,
                'file': this.dataForm.file,
                'teacherName': this.dataForm.teacherName,
                'sum': this.dataForm.sum,
                'average': this.dataForm.average,
                'peopleNumber': this.dataForm.peopleNumber,
                // 'statu': this.dataForm.statu,
                'projectType': this.dataForm.projectType,
                'type': this.dataForm.type,
                'createTime': this.dataForm.createTime
              })
            }).then(({
              data
            }) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
